package ch1;

/**
 * @author oldliu
 * @since 1.0
 */
public class TestG2 {
    public static void main(String[] args) {
        int[] ar = {-8, 2, 4, 7, -1, 6, 7, 8, 10};
        for (int i = 0; i < ar.length; i++) {
            //0....i-1 ,i+1 ....ar.length-1
            //0....i-1 所有的数 <=ar[i],i+1 ....ar.length-1 >=ar[i]
            boolean left = true, right = true;//假定都满足
            for (int m = 0; m < i; m++) {
                if (ar[m] > ar[i]) {
                    left = false;
                    break;
                }
            }
            for (int n = i + 1; n < ar.length; n++) {
                if (ar[n] < ar[i]) {
                    right = false;
                    break;
                }
            }
            if(left&&right){
                System.out.println("找到了，这个数是"+ar[i]+",位置在"+i);
                return;
            }
        }
        System.out.println("没有！");
    }
}
